package com.hue.gulimail.gulimailproduct.web;

import com.hue.gulimail.gulimailproduct.service.SkuInfoService;
import com.hue.gulimail.gulimailproduct.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;

@Controller
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId, Model model) {
        try {
            SkuItemVo skuItemVo = skuInfoService.getSkuItemVo(skuId);
            model.addAttribute("item", skuItemVo);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "item";
    }

    @GetMapping("/{skuId}")
    @ResponseBody
    public SkuItemVo testItem(@PathVariable("skuId") Long skuId) {
        SkuItemVo skuItemVo = null;
        try {
            skuItemVo = skuInfoService.getSkuItemVo(skuId);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return skuItemVo;
    }

}
